﻿@using FFLTask.GLB.Global.Enum
@using Global.Core.Helper
@using Global.Core.ExtensionMethod
@model FFLTask.SRV.ViewModel.Task.Content._PublishModel

<table id="edit_column_@TaskProcess.Publish">
    <tr>
        <th class="first_column">
            项目：
        </th>
        <td colspan="3">
            @Html.EditorFor(m => m.CurrentProject, "Project/_DropDownListLinkedProject")
        </td>
    </tr>
    <tr>
        <th>
            父任务：
        </th>
        <td colspan="3">
            @Html.EditorFor(m => m.Parent, "_SearchByIdOrTitle")
        </td>
    </tr>
    <tr>
        <th class="first_column">
            标题：
        </th>
        <td colspan="3">
            @Html.TextBoxFor(m => m.Title, new { style = " width: 406px;" })
            <br />
            @Html.ValidationMessageFor(m => m.Title)
        </td>
    </tr>
    <tr>
        @*top_align is necessary?*@
        <th class="top_align first_column">
            内容：
        </th>
        <td class="textarea" colspan="3">
            @Html.TextAreaFor(m => m.Body, new { style = "width:480px; height:100px;" })
        </td>
    </tr>
    <tr>
        <th class="top_align first_column">
            附件：
        </th>
        <td colspan="3">
            @Html.Partial("~/Views/Task/_UpLoadFiles.cshtml", new ViewDataDictionary { { "Belong", TaskProcess.Publish } })
            @Html.Partial("_Attachments", Model.Attachments, new ViewDataDictionary { { "TaskId", ViewContext.RouteData.Values["taskId"] } })
        </td>
    </tr>

    <tr>
        <th class="first_column">
            难度：
        </th>
        <td class="second_column">
            @Html.DropDownListFor(m => m.SelectedDifficulty, Model.AllDifficulties.GetSelectListItems<TaskDifficulty>(), "----")
        </td>
        <th class="third_column">
            工时(分钟)：
        </th>
        <td class="fourth_column">
            @Html.TextBoxFor(m => m.ExpectedWorkPeriod)
        </td>
    </tr>
    <tr>
        <th>
            优先级：
        </th>
        <td>
            @Html.DropDownListFor(m => m.SelectedPriority, Model.AllPriorities.GetSelectListItems<TaskPriority>(), "---")
        </td>
        <th>
            预计完成时间：
        </th>
        <td>
            @Html.EditorFor(m => m.ExpectedComplete)
        </td>
    </tr>
    <tr>
        <th>
            验收人：
        </th>
        <td>
            @Html.DropDownListFor(m => m.SelectedAccepterId, new SelectList(Model.Accepters, "Id", "Name"), "-----")
        </td>
        <th>
            虚任务：
        </th>
        <td>
            @Html.CheckBoxFor(m => m.Virtual)
            @Html.ValidationMessageFor(m => m.Virtual)
        </td>
</table>
<script type="text/javascript">
    //TODO: not a good practise set a public variable here
    //but it should be used in anthor place: Edit.cshtml to enable/disable it
    //don't know elegent way to deal with it now
    var editorBody;
    $(document).ready(function () {
        KindEditor.ready(function (K) {
            editorBody = K.create('textarea[name="@Html.NameFor(m=>m.Body)"]', {
                allowFileManager: false,
                @Html.Partial("KindEditorItems/_Simple")
            });
            var $publishEdit = $("checkbox[edit='@TaskProcess.Publish']");
            if ($publishEdit.length > 0 &&
                !$publishEdit.is(":checked")) {
                editorBody.readonly(true);
            }
        });

        $("#@Html.IdFor(m => m.Virtual)").click(function () {
            var $workPeriod = $("#@Html.IdFor(x => x.ExpectedWorkPeriod)");
            if ($(this).is(":checked")) {
                $workPeriod.val("").attr("disabled", "disabled");
            }
            else {
                $workPeriod.removeAttr("disabled");
            }
        });
    });
</script>
